
/**
 * @Author: 陈瑞鹏
 * @Date:   2022-12-07 16:56:55
 * @Last Modified by:   陈瑞鹏
 * @Last Modified time: 2022-12-09 14:43:05
 */
import gameCtr from "../ctrs/gameCtr";
import BaseGameComponent from "../libs/core/BaseGameComponent";
import { PureMVCEvents } from "../libs/core/PureMVCEvents";
import { INotification } from "../libs/pureMvc/Interfaces";

const { ccclass, property } = cc._decorator;

@ccclass

export default class zbCom extends BaseGameComponent {

  @property({ type: cc.Node, tooltip: "整备按钮" })
  zbBtn: cc.Node = null;

  @property({ type: cc.Node, tooltip: "1按钮" })
  Btn_1: cc.Node = null;

  @property({ type: cc.Node, tooltip: "2按钮" })
  Btn_2: cc.Node = null;

  @property({ type: cc.Node, tooltip: "3按钮" })
  Btn_3: cc.Node = null;

  @property({ type: cc.Node, tooltip: "4按钮" })
  Btn_4: cc.Node = null;

  @property({ type: cc.Node, tooltip: "5按钮" })
  Btn_5: cc.Node = null;

  @property({ type: cc.Node, tooltip: "6按钮" })
  Btn_6: cc.Node = null;

  public onEnable(): void {
    super.onEnable();
  }

  public listNotificationInterests(): string[] {
    return [PureMVCEvents.ON_ZBCOM_UDPATE];
  }

  public handleNotification(notification: INotification): void {
    let etName = notification.getName();
    switch (etName) {
      case PureMVCEvents.ON_ZBCOM_UDPATE:
        for (let i = 1; i < 7; i++) {
          let item = this.node.getChildByName(i + "Btn");
          if (Number(gameCtr.ins.curretRanks) == i) {
            item.getChildByName("check").active = true;
            item.getChildByName("Background").active = false;
          } else {
            item.getChildByName("check").active = false;
            item.getChildByName("Background").active = true;
          }
        }
        break;
    }
  }

  onBtnClick(e, key) {
    if (key == gameCtr.ins.curretRanks) return;
    gameCtr.ins.curretRanks = key;
    this.sendNotification(PureMVCEvents.ON_ZBCOM_UDPATE);
    this.sendNotification(PureMVCEvents.ON_ZBCOM_OPEN);
  }
}